package com.wyd.resourcetj.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.wyd.resourcetj.dao.IConsume_LogDao;
import com.wyd.resourcetj.model.Consume_Log;
import com.wyd.resourcetj.service.IConsume_LogService;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * Consume_LogController
 */
@RestController
@RequestMapping(path ="/consume_log",method = RequestMethod.GET)
public class Consume_LogController {

    @Resource
    private IConsume_LogDao consume_LogDao;

    @Resource
    private IConsume_LogService consume_LogService;





    @ApiOperation(value = "查询所有")

    @GetMapping(value = "/findLog")
        public Map findAll(){
 
         List<Consume_Log> list = consume_LogDao.findAll();
     
     Map<String,Object> map = new HashMap<String, Object>();
     map.put("code", 0);
     map.put("msg", "查询成功");
     map.put("count", list.size());
     map.put("data", list);
     
     
     return map;
 
        }




    @ApiOperation(value = "添加资源使用日志",notes="添加资源使用日志")
	  
    @PostMapping()
      
      public Consume_Log add(@RequestBody Consume_Log c) {
          
          return consume_LogDao.save(c);
          
      }


      /* @ApiOperation(value = "根据编号删除资源使用日志",notes="根据编号删除资源使用日志")
      @ApiImplicitParam(name="id",value ="资源使用日志编号",required=true,paramType ="path")
      @DeleteMapping(value ="/{id}")
        public void del(@PathVariable Integer id) {
            
            consume_LogDao.deleteById(id);
             
        
            
        } */

        /* @ApiOperation(value = "根据编号删除使用日志",notes="根据编号删除使用日志")
        @ApiImplicitParams({
         @ApiImplicitParam(name="n",value ="0 删除，1 恢复",required=true,paramType ="path"),
        @ApiImplicitParam(name="id",value ="使用日志编号",required=true,paramType ="path")
        })
        @PutMapping(value = "/{id}/{n}")
          public void del(@PathVariable Integer id,@PathVariable Integer n) {
              
            consume_LogDao.deleteConsume_Log(id, n);
               
          
              
          } */

          @ApiOperation(value = "根据编号删除日志",notes="根据编号删除日志")
          @ApiImplicitParam(name="id",value ="资源编号",required=true,paramType ="path")
          @DeleteMapping(value ="/{id}")
            public void del(@PathVariable Integer id) {
                
              consume_LogDao.deleteById(id);
                 
            
                
            } 


        @ApiOperation(value = "查询所有资源使用日志",notes = "查询所有资源使用日志")
        @PostMapping(value ="/findAll")
        public List<Consume_Log> findAllConsume_Log(){
            
           
                List<Consume_Log> list=new ArrayList<Consume_Log>();

                list=consume_LogDao.findAll();


            return list;
        }


       /*  @ApiOperation(value="根据编号修改离开时间",notes = "根据编号修改离开时间")
        @ApiImplicitParams({
          @ApiImplicitParam(name="cardNo",value ="会员卡号",required=true,paramType ="path"),
          @ApiImplicitParam(name="outTime",value ="离开时间",required=true,paramType ="path")
          
      })
      @PutMapping(value = "/editOutTime/{cardNo}/{outTime}")
      public int editOutTime(@PathVariable String  cardNo,@PathVariable Date outTime) {
          
          return consume_LogDao.updateOutTime(cardNo,outTime);
          
      } */



      @ApiOperation(value = "查询单个资源使用日志",notes = "查询单个资源使用日志")
      @ApiImplicitParam(name="card_no",value ="卡号",required=true,paramType ="path")
      @PostMapping(value ="/findAllOne/{card_no}")
      public Consume_Log findOnrConsume_Log(@PathVariable String card_no){
          
         
            

        Consume_Log   l=consume_LogDao.findOne(card_no);


          return l;
      }


      @ApiOperation(value = "刷卡",notes = "刷卡")
      @ApiImplicitParams({
          @ApiImplicitParam(name = "read_room_id",value = "资源室编号",required = true,paramType = "path")
      })
      @PutMapping("/shuaka/{read_room_id}/{card_no}/{inOrOut}")
      public Consume_Log enter(@PathVariable Integer read_room_id,@PathVariable String card_no,@PathVariable boolean inOrOut){
          return consume_LogService.swipingCard(read_room_id, card_no, inOrOut);
      }



    
}